from interface_practice.frame.apis.contract.contact import Contract


class Department(Contract):
    '''
    部门管理接口
    '''

    def create(self, data):
        '''
        部门的创建
        '''
        # 指定 url
        url = "/department/create"
        # 组装参数
        param = {
            "access_token": self.access_token
        }
        # 调用发送请求的方法，发起对应的请求
        r = self.send(method="POST", url=url, params=param, tools="requests", json=data)
        # 返回接口调用的响应结果
        return r

    def get(self):
        '''
        部门的获取
        '''
        # 指定 url
        url = "/department/simplelist"
        # 组装参数
        param = {
            "access_token": self.access_token
        }
        # 调用发送请求的方法，发起对应的请求
        r = self.send(method="GET", url=url, params=param, tools="requests")
        # 返回接口调用的响应结果
        department_list = [depart.get("id") for depart in r.json().get("department_id")]
        return department_list

    def update(self, data):
        '''
        部门的修改
        '''
        # 指定 url
        url = "/department/update"
        # 组装参数
        param = {
            "access_token": self.access_token
        }
        # 调用发送请求的方法，发起对应的请求
        r = self.send(method="POST", url=url, params=param, tools="requests", json=data)
        # 返回接口调用的响应结果
        return r

    def delete(self, department_id):
        '''
        部门的删除
        '''
        # 指定 url
        url = "/department/delete"
        # 组装参数
        param = {
            "access_token": self.access_token,
            "id": department_id
        }
        # 调用发送请求的方法，发起对应的请求
        r = self.send(method="GET", url=url, params=param, tools="requests")
        # 返回接口调用的响应结果
        return r
